package com.thomsonreuter.search.compare.excutor;


import com.thomsonreuter.search.compare.config.PropertyConfig;
import com.thomsonreuter.search.compare.constants.CompareConstants;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.util.Objects;

public class QueryTemplate {

    public static String getQueryStr() throws IOException {

        return IOUtils.toString(Objects.requireNonNull(QueryTemplate.class.getClassLoader().getResourceAsStream("sampler.json")))
                .replace(CompareConstants.TEMPLATE_SAMPLE_TOTAL_SIZE, PropertyConfig.getInstance().getProperties(CompareConstants.SAMPLE_SIZE));
    }


    public static String getPageQueryStr() throws IOException {

        return IOUtils.toString(Objects.requireNonNull(QueryTemplate.class.getClassLoader().getResourceAsStream("page.json")));

    }

    public static String getIsinDocQueryStr(String isin) throws IOException {

        return IOUtils.toString(Objects.requireNonNull(QueryTemplate.class.getClassLoader().getResourceAsStream("isindocuments.json")))
                .replace("$ISIN$", isin);

    }

    public static String getEikonDocQueryStr(String docid) throws IOException {

        return IOUtils.toString(Objects.requireNonNull(QueryTemplate.class.getClassLoader().getResourceAsStream("checkdocineikon.json")))
                .replace("$ID$", docid);

    }
    public static String getNextPageQueryStr(String scrollId) throws IOException {
        return IOUtils.toString(Objects.requireNonNull(QueryTemplate.class.getClassLoader().getResourceAsStream("scrollpage.json")))
            .replace(CompareConstants.TEMPLATE_SCROLLID, scrollId);

    }

}
